package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/*
* 通用接口
* */
@RestController
@RequestMapping("/admin/common")
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;

    /**
     * 文件上传
     * @param file
     * @return {@code Result }
*/
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {

        String originalFilename= file.getOriginalFilename();  //获取文件名
        String endName =originalFilename.substring(originalFilename.lastIndexOf("."));  //获取文件后缀名
        String uniqueFileName=UUID.randomUUID().toString()+endName;  //(生成随机数+文件名).后缀

       String url=aliOssUtil.upload(file.getBytes(),uniqueFileName);
        System.out.println("no");
       return Result.success(url);

    }

}
